package main

import (
	"context"
	"flag"
	"fmt"
	casePb "git.code.oa.com/MoreFunAutomationTest/AutoTestPlatform/proto/cases"
	"git.code.oa.com/trpc-go/trpc-go/client"
	"git.code.oa.com/trpc-go/trpc-naming-polaris/selector"
)

func init() {
	selector.RegisterDefault()
}

func main2() {
	ctx := context.Background()
	clientProxy := casePb.NewCaseManageClientProxy()

	req := &casePb.CaseListRequest{
		ProjectId: "1",
	}
	username := "it's me"
	rsp, err := clientProxy.CaseList(ctx, req, client.WithTarget("ip://127.0.0.1:8000"), client.WithMetaData("userId", []byte(username)))
	if err != nil {
		fmt.Println("err: " + err.Error())
		return
	}
	fmt.Println(rsp)
	// log.Printf("req:%v, rsp:%v, err:%v", req, rsp, err)
}

func main3() {

	ctx := context.Background()
	// reqhead := &trpc.RequestProtocol{}
	opts := []client.Option{
		client.WithNamespace("Production"),
		client.WithTarget("polaris://gdp.mfat.case-server-release-v4"),
		//client.WithReqHead("Host:mfat.device-server"),
		// client.WithReqHead(reqhead),
		client.WithProtocol("trpc"),
	}

	clientProxy := casePb.NewCaseManageClientProxy(opts...)
	caseIds := "647,648"
	req := &casePb.CaseListRequest{
		ProjectId: "KiHan",
		CaseIds:   &caseIds,
	}
	username := "it's me"
	rsp, err := clientProxy.CaseList(ctx, req, client.WithMetaData("userId", []byte(username)))
	if err != nil {
		fmt.Println("err: " + err.Error())
		return
	}
	fmt.Println(rsp)
}

func main() {

	addr := flag.String("addr", "127.0.0.1", "ip地址")
	port := flag.String("port", "8000", "端口")
	project := flag.String("project", "1", "项目id")
	flag.Parse()
	ctx := context.Background()
	clientProxy := casePb.NewCaseManageClientProxy()

	req := &casePb.CaseListRequest{
		ProjectId: *project,
	}
	username := "it's me"
	rsp, err := clientProxy.CaseList(ctx, req, client.WithTarget(fmt.Sprintf("ip://%s:%s", *addr, *port)), client.WithMetaData("userId", []byte(username)))
	if err != nil {
		fmt.Println("err: " + err.Error())
		return
	}
	fmt.Println(rsp)
	// log.Printf("req:%v, rsp:%v, err:%v", req, rsp, err)
}
